package com.cskaoyan.controller;

import com.cskaoyan.bean.Ad;
import com.cskaoyan.service.AdService;
import com.cskaoyan.vo.AdVo;
import com.cskaoyan.vo.BaseRespVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ description:
 * - 广告的
 * - 显示,增加,修改,删除
 * @ author:台
 **/

@RestController
public class AdController {

    @Autowired
    AdService adService;

    @RequestMapping("admin/ad/list")
    public BaseRespVo adList(Integer page, Integer limit, String sort, String order){
        AdVo adVo = adService.adList(page,limit,sort,order);
        BaseRespVo baseRespVo = BaseRespVo.ok(adVo);
        return baseRespVo;
    }

    @RequestMapping("admin/ad/delete")
    public BaseRespVo adDelete(@RequestBody Ad ad){
        adService.adDelete(ad);
        return BaseRespVo.ok();
    }

    @RequestMapping("admin/ad/create")
    public BaseRespVo adCreate(@RequestBody Ad ad){
        Ad data = adService.adCreate(ad);
        return BaseRespVo.ok(data);
    }

    @RequestMapping("admin/ad/update")
    public BaseRespVo adUpdate(@RequestBody Ad ad){
        Ad data = adService.adUpdate(ad);
        return BaseRespVo.ok(data);
    }
}
